package com.liankuan.console.service.ServiceImpl;

import com.liankuan.console.controller.vo.request.User.UserDtoIO;
import com.liankuan.console.dto.UserRole;
import com.liankuan.console.repository.UserRoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserRoleServiceImpl {
    private final UserRoleRepository userRoleRepository;

    @Autowired
    public UserRoleServiceImpl(UserRoleRepository userRoleRepository) {
        this.userRoleRepository = userRoleRepository;
    }

    /**
     * 根据用户id获取用户的角色
     *
     * @param userId
     * @return
     */
    public UserRole findRoleByUserId(int userId) {
        return userRoleRepository.findByUserId(userId);
    }

    /**
     * 删除记录
     *
     * @param id
     */
    public void deleteByUserId(Integer id) {
        userRoleRepository.deleteByUserId(id);
    }

    /**
     * @param id
     */
    public void updateByUserId(Integer id, String role) {
        userRoleRepository.updateByUserId(id, role);
    }

    /**
     *  新增用户对应角色信息
     * @param userId
     * @param role
     */
    public void addUserRole(int userId, String role) {
        UserRole userRole = new UserRole();
        userRole.setUserId(userId);
        userRole.setRole(role);

        userRoleRepository.save(userRole);
    }
}
